package com.bkgy.modular.tbmodelpdiset.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bkgy.modular.tbmodelpdiset.entity.TbModelPdiSet;
import com.bkgy.modular.tbmodelpdiset.mapper.TbModelPdiSetMapper;
import com.bkgy.modular.tbmodelpdiset.service.TbModelPdiSetService;
import com.bkgy.sys.common.entity.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZhuHongKai
 * @version 1.0
 * @ClassName TbModelPdiSetService
 * @date 2022/12/13 16:15
 */
@Service
public class TbModelPdiSetServiceImpl extends ServiceImpl<TbModelPdiSetMapper, TbModelPdiSet> implements TbModelPdiSetService {
    @Resource
    private TbModelPdiSetMapper tbModelPdiSetMapper;

    /**
     * 分页条件查询
     * @param jsonObject
     * @return
     */
    @Override
    public ResultData findByPageData(JSONObject jsonObject) {
        // 根据传入的key获取pageIndex和pageSize
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        Integer pageSize = jsonObject.getInteger("pageSize");

        // 判断pageIndex和pageSize是否有值,没值给出提示
        if (pageIndex == null || pageSize == null) {
            return ResultData.ResultDataFaultSelf("分页参数没有传", null);
        }

        // 根据传入的key获取查询条件对象conditon
        JSONObject condition = jsonObject.getJSONObject("condition");

        // 调用自定义sql方法进行查询
        List<TbModelPdiSet> list = tbModelPdiSetMapper.findByPage((pageIndex - 1) * pageSize, pageIndex * pageSize, condition);
        Integer count = tbModelPdiSetMapper.findByDataCount(condition);
        return ResultData.ResultDataSuccess(list,count);
    }

    @Override
    public ResultData findByPageData2130(JSONObject jsonObject) {
        // 根据传入的key获取pageIndex和pageSize
        Integer pageIndex = jsonObject.getInteger("pageIndex");
        Integer pageSize = jsonObject.getInteger("pageSize");

        // 判断pageIndex和pageSize是否有值,没值给出提示
        if (pageIndex == null || pageSize == null) {
            return ResultData.ResultDataFaultSelf("分页参数没有传", null);
        }

        // 根据传入的key获取查询条件对象conditon
        JSONObject condition = jsonObject.getJSONObject("condition");

        // 调用自定义sql方法进行查询
        List<TbModelPdiSet> list = tbModelPdiSetMapper.findByPage2130((pageIndex - 1) * pageSize, pageIndex * pageSize, condition);
        Integer count = tbModelPdiSetMapper.findByData2130Count(condition);
        return ResultData.ResultDataSuccess(list,count);
    }
}
